<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
	<title>demo</title>
	<link rel="stylesheet" href="../../source/plugins/layui/css/layui.css" />
</head>
<body>
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">输入框</label>
    <div class="layui-input-block">
      <input type="text" name="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
    </div>
  </div>


  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script src="../../source/plugins/layui/layui.js"></script>
<script src="../../source/plugins/datatables/jquery-1.12.4.js"></script>
<script>
//Demo

layui.config({
    base: '../../source/js/'
}).use(['validator', 'form'], function() {
	var validator = layui.validator;
	var form = layui.form();
	//监听提交
  form.on('submit(formDemo)', function(data){
  	if(!validator.IsNumber($("[name='title']").val())){
  		$("[name='title']").addClass('layui-form-danger').focus();
  		layer.msg('必须填写数字', {icon: 5, anim: 6});
  		return false;
  	}
    return false;
  });
})
</script>
</body>
</html>